package com.qymerge.manage.base.controller;

import com.google.common.reflect.TypeToken;
import com.qymerge.manage.base.ro.BDMSaleLinesRO;
import com.qymerge.manage.base.service.IStoredProcedureService;
import com.qymerge.manage.core.bean.*;
import com.qymerge.manage.core.constant.ParamKey;
import com.qymerge.manage.core.utils.GsonUtil;
import com.qymerge.manage.core.utils.PrintCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 *
 * @author Xiao
 * @version 1.0.0
 * @date 2025/5/28 17:29
 */
@Controller
@RequestMapping("/storedProcedure")
public class IStoredProcedureManageController {

    @Autowired
    private IStoredProcedureService storedProcedureService;

    /**
     * 测试存储过程销售列表
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("getBDMSaleLinesByBillCode")
    public void getBDMSaleLinesByBillCode(HttpServletRequest request, HttpServletResponse response,

                     @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                     @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.listBDMSaleLines(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }

    /**
     * 更新凭证
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("dwd_MCRS_MDM_sp_Voucher")
    public void dwd_MCRS_MDM_sp_Voucher(HttpServletRequest request, HttpServletResponse response,

                                        @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                                        @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.dwd_MCRS_MDM_sp_Voucher(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }

    /**
     * 更新应收单
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("dwd_MCRS_BDM_sp_SaleLines")
    public void dwd_MCRS_BDM_sp_SaleLines(HttpServletRequest request, HttpServletResponse response,

                     @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                     @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.dwd_MCRS_BDM_sp_SaleLines(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }

    /**
     * 更新分公司科目数据
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("dwd_MCRS_MDM_Sp_ActualDataExtra")
    public void dwd_MCRS_MDM_Sp_ActualDataExtra(HttpServletRequest request, HttpServletResponse response,

                                          @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                                          @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.dwd_MCRS_MDM_Sp_ActualDataExtra(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }

    /**
     * 更新余额
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("dwd_MCRS_MDM_sp_InventoryBalance")
    public void dwd_MCRS_MDM_sp_InventoryBalance(HttpServletRequest request, HttpServletResponse response,

                                                @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                                                @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.dwd_MCRS_MDM_sp_InventoryBalance(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }

    /**
     * 更新生产成本
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("dwd_MCRS_Report_SP_In_Out_Cost")
    public void dwd_MCRS_Report_SP_In_Out_Cost(HttpServletRequest request, HttpServletResponse response,

                                          @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                                          @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.dwd_MCRS_Report_SP_In_Out_Cost(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }

    /**
     * 更新销售数据
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("dwd_MCRS_Report_SP_In_Sales")
    public void dwd_MCRS_Report_SP_In_Sales(HttpServletRequest request, HttpServletResponse response,

                                          @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                                          @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<BDMSaleLinesRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<BDMSaleLinesRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        BDMSaleLinesRO ro = paramValue.getData();

        ActionResultRO data = storedProcedureService.dwd_MCRS_Report_SP_In_Sales(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data, callback);
    }


}
